
function header() {
    class second {
        constructor() {
            this.listA = $('.nav_main_ul_li>a')
            this.contentBox = $('.nav_inner_warp')
            this.nav_inner = $('.nav_inner_warp').find('.nav_inners')
            this.navUl = $('.nav_main_ul')
            this.navMubu = $('.nav_mubu')//黑色背景
            this.listA_div = $('.nav_inner_warp')
            this.navh_baiseLise = $('.navh_baiseLise')
            this.navg = $('.navg_warp')
            this.mubu = $('.nav_mubu')
            this.navs = $('.nav_main')
            this.listLi = $('.nav_main_ul_li')
            //执行
            this.navUrl()
            //页面小图标购物车
            this.crtLi()
            //soso框
            this.soso()
            this.flag = null
        }
        init() {
            let _this = this
            // console.log(this.listLi);
            //划过当前标签给添加class类
            this.listA.hover(function () {
                //获取当前元素的index索引
                let nav_inner = $('.nav_inner_warp').find('.nav_inners')
                let istAindex = $(this).index('.listA')
                console.log(istAindex);
                //整体删除class
                nav_inner.removeClass('actives')
                //滑过的加入class
                nav_inner.eq(istAindex).addClass('actives')
                //滑过当前元素给全部元素删除类
                _this.listA.removeClass('active')
                //给当前元素添加类
                $(this).addClass('active')

            }, function () {
                // 
            })

            this.listLi.hover(() => {
                this.navh_baiseLise.stop(true).animate({
                    height: 640
                }, function () {
                    _this.navMubu.css('position', 'fixed')
                })

                //显示整体list box
                this.contentBox.stop(true).animate({
                    height: 640
                })

                this.mubu.addClass('activess')
            }, () => {
                this.navh_baiseLise.stop(true).animate({
                    height: 0
                }, function () {
                    //动作完成移除当前所有标签的类
                    _this.listA.removeClass('active')
                    _this.navMubu.attr('style', '')
                })
                //显示每个list-box
                this.contentBox.stop(true).animate({
                    height: 0
                })

                this.mubu.removeClass('activess')
                //把页面用到的样式之后，移除用不到直接删除
                // this.mubu.removeAttr('style')
            })

            //点击叉叉让白色画布的高为零
            $('.icon-chahao').on('click', function () {
                _this.navh_baiseLise.stop(true).animate({
                    height: 0
                }, function () {
                    //动作完成移除当前所有标签的类
                    _this.listA.removeClass('active')
                    _this.navMubu.attr('style', '')
                })
                //显示每个list-box
                _this.contentBox.stop(true).animate({
                    height: 0
                })
                _this.mubu.removeClass('activess')
            })

            //滑过当前二级菜单给类名
            $('.nav_inner_ul .erLi>a').hover(function () {
                $('.nav_inner_ul .erLi>a').removeClass('activeJ')
                $(this).addClass('activeJ')
                // $(this).next().animate({
                //     left: 0,
                //     opacity: 1
                // })
            }, function () {
            })

            $('.nav_inner_ul .erLi').on('mouseover', function () {
                console.log($(this).find('.erLi .nav_three_warp').find('.nav_three'));
                $(this).find('.nav_three_warp').find('.nav_three')
                $(this).find('.nav_three_warp').find('.nav_three').stop(true).animate({
                    opacity: 1,
                    left: 0
                })
            })
            $('.nav_inner_ul .erLi').on('mouseout', function () {
                $(this).find('.nav_three_warp').find('.nav_three').stop(true).animate({
                    opacity: 0,
                    left: -106
                })
            })

            $('.nav_inner_ul .erLi .nav_three_warp').find('.nav_three').hover(function () {
                $(this).show()
            }, function () {
                $(this).stop(true).animate({
                    opacity: 0,
                    left: -106
                })
            })

            $('.nav_inner_ul .erLi').find('.nav_three_warp').find('.nav_three').on('mouseover', function (e) {
                $(this).css({
                    opacity: 1,
                    left: 0
                })
            })

            //滑过strong给其添加动画下划线效果

            $('.nav_main_ul_li .nav_inner_warp .nav_title_warp').find('strong').find('.nav_Title').on('mouseover', function () {
                $('.tiao').addClass('activeLR')
            })
            $('.nav_main_ul_li .nav_inner_warp .nav_title_warp').find('strong').find('.nav_Title').on('mouseout', function () {
                $('.tiao').removeClass('activeLR')
            })

            //判断用户是否登录成功，登录成功会储存到localStorage用户名
            if (localStorage.getItem('username')) {
                //注册登录隐藏
                $('.login_register_l').hide()
                //用户信息显示
                $('.login_register_r').show()

                $('.user_name').html(localStorage.getItem('username'))
            }
            //划过登录信息出现效果
            $('.login_register_r').hover(function () {
                $('.user_login_xinxi').stop(true).animate({
                    height: 480
                })
            }, function () {
                $('.user_login_xinxi').stop(true).animate({
                    height: 0
                })
            })
            //XX按钮
            $('.icon-chahao1').on('click', function () {
                $('.nubust').css('display', 'none')
            })

            //划过登录信息li给类名active
            $('.login_register_r').find('li').hover(function () {
                $(this).addClass('active').siblings().removeClass('active')
            })
            //确定退出
            $('.ggt').on('click', function () {
                _this.flag = true
                $('.nubust').css('display', 'none')
                console.log(_this.flag);
                if (_this.flag) {
                    if (localStorage.getItem('username')) {
                        localStorage.removeItem('username')
                    }
                    $('.login_register_l').show()
                    //用户信息显示
                    $('.login_register_r').hide()
                }
            })
            //确定取消
            $('.jiarugouwuchet').on('click', function () {
                _this.flag = false
                $('.nubust').css('display', 'none')
                console.log(_this.flag);
                if (_this.flag) {
                    if (localStorage.getItem('username')) {
                        localStorage.removeItem('username')
                    }
                    $('.login_register_l').show()
                    //用户信息显示
                    $('.login_register_r').hide()
                }
            })
            //退出当前登录的用户，删除本都存储，隐藏当前用户块框
            $('.tc_btn').on('click', function () {
                $('.nubust').css('display', 'block')
                $('.nubust').animate({
                    opacity: 1
                })

            })
            //退出登录
            $('.ggt').hover(function () {
                $(this).addClass('active')
            }, function () {
                $(this).removeClass('active')
            })

        }
        //传递给下一个页面点击的信息：
        navUrl() {
            // console.log(history.go(-1));
            $('.nav_Title').hover(function () {
                $(this).attr('src', 'http://127.0.0.1/SAMSUNGproject/frontend/list.html')
            })
            // console.log($('.nav_Title'));
            $('.nav_Title').on('click', function () {
                console.log(location.href);
                // 获取当前点击的src然后进行添砖携带数据
                let navURL = `${$(this).attr('src')}?${$(this).html()}`
                location.href = navURL
            })
        }
        crtLi() {
            //点击以后直接放入查看本地存储实时更新购物车子
            //页面购物车效果

            //根据本地存储渲染商品

            let localS = {}
            if (localStorage.getItem('shopS')) {
                localS = JSON.parse(localStorage.getItem('shopS'))
            } else {
                localS = {}
            }
            // 所有数据的接口地址： http://127.0.0.1/SAMSUNGproject/backend/allCom.php
            $.ajax({
                url: 'http://127.0.0.1/SAMSUNGproject/backend/allCom.php',
                method: 'get',
                dataType: 'json'
            }).then((result) => {
                let localSname = Object.keys(localS)
                let num = 0 // 根据渲染数量次数，渲染有多少件商品
                $.each(localSname, function (i, shopNmae) {
                    // console.log(shopNmae.substring(5));
                    $.each(result, function (index, element) {

                        if (shopNmae.substring(5) === element.sid) {
                            // console.log(element);
                            let cloneConent = $('.crtList_content').eq(0).clone(true, true)
                            cloneConent.attr('id', element.sid)
                            cloneConent.find('.crtList_img img').attr('src', element.url)
                            cloneConent.find('.crtList_title p').html(element.title)
                            cloneConent.find('.crtList_jg').html(`￥${element.price}`)
                            cloneConent.find('.crtList_title span').eq(0).html($('.buy_Bar_item_txt_pz span').eq(0).html())
                            cloneConent.find('.crtList_title span').eq(1).html($('.buy_Bar_item_txt_pz span').eq(1).html())
                            cloneConent.find('.crtList_color').css('backgroundColor', $('.buy_Bar_item_txt_color span').find('i').css('backgroundColor'))
                            cloneConent.css({
                                display: 'flex'
                            })
                            $('.crtList_item').append(cloneConent)
                            //设置商品数量
                            num++
                            $('.sLk span').html(num)
                            $('.goShoplist_bottom_L span').eq(0).find('i').html(num)
                        }
                    })
                })
                calc()
            })

            //计算总价函数封装

            function calc() {
                let zj = 0
                $('.crtList_content[id]').each(function (index, element) {
                    zj += parseFloat($(element).find('.crtList_jg').html().substring(1))
                })
                $('.goShoplist_bottom_L span').eq(1).html("￥" + zj)
            }
            //判断可见的渲染是否大于0大于零让购物车显示,小于零让无宝贝购买框显示
            // console.log(Object.keys(localS).length);
            $('.sLk').parents('li').hover(function (e) {
                // console.log(e.target.nodeName);
                if (e.target.nodeName === 'LI') {
                    // console.log(parseInt($('.crtList_content:visible').length));
                    //判断本地存储的值是否存在,存在显示,不存在显示购物车无宝贝!
                    // $('.goShoplist').hide()
                    // $('.noShoplist').hide()
                    if (Object.keys(localS).length === 0) {
                        $('.noShoplist').show()
                        $('.goShoplist').hide()
                    }
                    if (Object.keys(localS).length > 0) {
                        $('.goShoplist').show()
                        $('.noShoplist').hide()
                    }
                }
            }, function () {
                $('.noShoplist').hide()
                $('.goShoplist').hide()

            })
            //小图部删除操作
            $('.crtList_item').on('click', '.icon-chahao1', function () {
                if (window.confirm('移除了呦!')) {
                    $(this).parents('.crtList_content').remove()
                }
                deleLcal($(this).parents('.crtList_content').attr('id'))
                // console.log($(this).parents('.crtList_content').attr('id'));
                if (Object.keys(localS).length === 0) {
                    $('.goShoplist').hide()
                    $('.noShoplist').show()
                }
                $('.sLk span').html(Object.keys(localS).length)
                $('.goShoplist_bottom_L span').eq(0).find('i').html(Object.keys(localS).length)
                calc()
            })
            //删除本都存储函数
            // console.log(localS);
            function deleLcal(id) {
                delete localS["cert_" + id] // 删除
                //再次存储
                localStorage.setItem('shopS', JSON.stringify(localS))
                console.log(Object.keys(localS).length);
                if (Object.keys(localS).length === 0) {
                    localStorage.removeItem('shopS')
                }
            }
            //点击跳转去购物车购买
            $('.gowuc').on('click', function () {
                location.href = 'http://127.0.0.1/SAMSUNGproject/frontend/cartlist.html'
            })
        }
        //taobao的接口soso
        //https://www.baidu.com/sugrec?pre=1&p=3&ie=utf-8&json=1&prod=pc&wd=%E6%B7%98%E5%AE%9D&csor=2&cb=taobao
        soso() {
            //文本框获取焦点给类名
            $('.soso').on('focus', function () {
                $(this).addClass('active')
                $('.sosoList').show()
            })
            //文本框失去焦点移除类名
            $('.soso').on('blur', function () {
                $(this).removeClass('active')
                $('.sosoList').hide()
            })
            //滑过li给类名
            $('.sosoList').on('mouseover', 'li', function () {
                $(this).addClass('active').siblings().removeClass('active')
            })
        }
    }
    //公共的头部底部外部引入调用头部所拥有的js文件
    new second().init()


    class Scroll {
        constructor() {
        }
        init() {
            this.backTop()
        }
        //回到顶部
        backTop() {
            //获取window滚动条的
            $(window).on('scroll', function () {
                let scrollTop = $(this).scrollTop()
                // console.log(scrollTop);
                //判断是否大于等于一定的值让回到顶部show
                if (scrollTop >= 500) {
                    //控制返回顶部的按钮出现：消失
                    $('.dingbu').show()
                    // console.log($('.dingbu'));
                } else {
                    $('.dingbu').hide()
                }
                $('.dingbu').on('click', function () {
                    //控制回到顶部的动作
                    $('html').stop(true).animate({
                        scrollTop: 0
                    })
                })
            })
        }
    }
    new Scroll().init()
}
export {
    header
}